package com.aaa.utils;

import com.aliyuncs.DefaultAcsClient;
import com.aliyuncs.exceptions.ClientException;
import com.aliyuncs.profile.DefaultProfile;
import com.aliyuncs.vod.model.v20170321.GetPlayInfoRequest;
import com.aliyuncs.vod.model.v20170321.GetPlayInfoResponse;
import com.aliyuncs.vod.model.v20170321.GetVideoPlayAuthRequest;
import com.aliyuncs.vod.model.v20170321.GetVideoPlayAuthResponse;

import java.util.List;

/**
 * @ClassName: AliyunVideoPath
 * @Description: TODO
 * @Author: 86139
 * @Date: 2021/9/15 21:45
 * @Version:1.0
 **/
public class AliyunVideoPath {
    public static DefaultAcsClient initVodClient(String accessKeyId, String accessKeySecret) throws ClientException {
        String regionId = "cn-shanghai";  // 点播服务接入区域
        DefaultProfile profile = DefaultProfile.getProfile(regionId, accessKeyId, accessKeySecret);
        DefaultAcsClient client = new DefaultAcsClient(profile);
        return client;
    }
    public static String getPlayAuth(String videoId) throws ClientException {
        DefaultAcsClient client = initVodClient("LTAI5t9TgeL2Jm3dzpyepty1", "JbqZo19QRdE7WS1xD5gfbDKGhdsq7v");
        GetVideoPlayAuthRequest request = new GetVideoPlayAuthRequest();
        GetVideoPlayAuthResponse response = new GetVideoPlayAuthResponse();
        request.setVideoId("2562ea9f30db45769a2785c9815fd940");
        response=client.getAcsResponse(request);
        System.out.println(response.getPlayAuth());
        return response.getPlayAuth();
    }
    //    获取文件路径  没有加密的可以播放
    public static  String getPlayUrL(String videoId) throws ClientException {
        DefaultAcsClient client = initVodClient("LTAI5t9TgeL2Jm3dzpyepty1", "JbqZo19QRdE7WS1xD5gfbDKGhdsq7v");
        GetPlayInfoRequest request = new GetPlayInfoRequest();
        request.setVideoId(videoId);
        GetPlayInfoResponse response = client.getAcsResponse(request);
        List<GetPlayInfoResponse.PlayInfo> playInfoList = response.getPlayInfoList();
        //播放地址
        String videoURL="";
        for (GetPlayInfoResponse.PlayInfo playInfo : playInfoList) {
            System.out.print("PlayInfo.PlayURL = " + playInfo.getPlayURL() + "\n");
            videoURL=playInfo.getPlayURL();
        }
        //Base信息
        System.out.print("VideoBase.Title = " + response.getVideoBase().getTitle() + "\n");
        return videoURL;
    }
}
